
export function createTimeStamp() {
    return parseInt(new Date().getTime() / 1000)
}

export function createNonceStr() {
    return Math.random().toString(36).substr(2, 15)
}

/**
 * 参数加密
 * @param param
 * @returns {string}
 */
function encode(param) {
    let array = [];
    // json 对象转数组
    let key, value;
    for (key in param) {
        value = param[key]
        // 过滤空参数  null  undefined 空字符串
        if (value || value === 0) {
            array.push(key)
        }
    }
    // 数组默认按照ascii排序
    array.sort();
    let result = [];
    //顺序kv拼接
    array.forEach((key) => {
        let tmp = [];
        tmp[0] = key;
        let element = param[key];
        if (Array.isArray(element)) {
            tmp[1] = JSON.stringify(element)
            // console.log("api.js",'encode.json ',JSON.stringify(element),'\n join ',element.join(','),'\ntmp',tmp[1]);
        } else {
            tmp[1] = element
        }
        result.push(tmp.join('='))
    });
    result.push('key=' + APPSECRET);
    let finalStr = result.join('&');
    // console.log('sort.js', '.sort ', result, ' join ', finalStr);
    //转md5
    let md = md5(finalStr).toUpperCase();
    // console.log('sort.js', '.sort', md);
    return md;
}
